import { downloadExcel } from '@/utils/download'

import Http from '@/utils/httpUtil'
const generateId = () => (Math.floor(Math.random() * 10e15)).toString(32)

// 新增组织
export const addOrg = param => Http.post(`${'ucenter/org/add'}?uuId=${generateId()}`, param)

// 获取分页列表
export const getOrgList = param => Http.get('ucenter/org/list', param)

// 获取所有组织列表
export const getAllOrgList = param => Http.get('ucenter/org/all', param)

/**
 * 根据用户id获取组织列表
 */
export const getOrgListByUserId = id => Http.get(`${'ucenter/org/listByUser'}/${id}`)

// 获取所有组织（树状）
export const getOrgTree = param => Http.get('ucenter/org/tree', param)

// 获取组织单元下的列表
export const orgSubList = param => Http.get('ucenter/org/type/list', param)

// 批量删除组织信息
export const deleteOrg = param => Http.post('ucenter/org/delete', param)

// 编辑组织
export const updateOrg = param => Http.post('ucenter/org/edit', param)

// 根据id获取组织详情
export const findOneOrg = param => Http.get(`${'ucenter/org/info'}/${param.id}`, param)

// 获取组织树
export const getOrgTreeList = param => Http.get('ucenter/org/tree', param)

// 获取已被选的组织id
export const getOrgUsedList = param => Http.get('ucenter/org/listUsed')

// 获取组织树 分层数据
export const listOrgByParentId = param => Http.get('ucenter/org/listOrgByParentId', param)

// 获取组织导出
export const orgExport = param => Http.get('ucenter/org/export', param, { responseType: 'arraybuffer' }).then(downloadExcel)

// 下载导入模板
export const orgExportTemplate = param => Http.get('ucenter/org/getImportTmp', param, { responseType: 'arraybuffer' }).then(data => downloadExcel(data, '导入模板'))

// 导入组织
export const orgImportUrl = Http.makeUrl('ucenter/org/import')
